'use strict';

/**
 * @description 入住信息表模型
 * */
module.exports = app => {
  const { INTEGER, DATE, TEXT, STRING } = app.Sequelize;

  const Appointment = app.model.define('appointment', {
    startTime: {
      type: DATE,
      allowNull: false,
      comment: '开始时间',
    },
    endTime: {
      type: DATE,
      allowNull: false,
      comment: '结束时间',
    },
    phoneNum: {
      type: STRING,
      allowNull: false,
      comment: '联系人电话号码',
    },
    persons: {
      type: STRING,
      allowNull: false,
      comment: '入住人列表',
    },
    comment: {
      type: TEXT,
      allowNull: true,
      comment: '入住信息备注',
    },
    status: {
      type: INTEGER,
      allowNull: false,
      comment: '状态 1-待房东回复 2-房东拒绝 3-房东同意 4-已被他人预约',
    },
    reason: {
      type: TEXT,
      allowNull: true,
      comment: '房东原因',
    },
    uid: {
      type: INTEGER,
      allowNull: false,
      comment: '用户id',
    },
    houseId: {
      type: INTEGER,
      allowNull: false,
      comment: '房屋id',
    },
  });

  Appointment.associate = () => {
    app.model.Appointment.belongsTo(app.model.User, {
      foreignKey: 'uid',
    });
    app.model.Appointment.belongsTo(app.model.House, {
      foreignKey: 'houseId',
    });
  };

  return Appointment;
};
